package com.hzdesk.media.koreabatchmatvector.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.inter.IDeleteFileDialogListener;


/**
 * @author Mr.Lee
 */
public class DeleteFileDialog extends Dialog {


    private TextView nameText;
    private TextView tv_titile;
    private Button ok, cancel;
    private String name;  // 内容
    private String title;

    private  IDeleteFileDialogListener mIDeleteFileDialogListener = null;
    public void setmIDeleteFileDialogListener(IDeleteFileDialogListener mIDeleteFileDialogListener) {
        this.mIDeleteFileDialogListener = mIDeleteFileDialogListener;
    }
    public DeleteFileDialog(Context context,  String string,String mtitle) {
        super(context, R.style.MyDialog);
        this.name = string;
        this.title = mtitle;
    }


    @Override
    protected void onCreate(Bundle paramBundle) {
        // TODO Auto-generated method stub
        super.onCreate(paramBundle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.delete_file_dialog);
        initViews();
        initEvens();
    }

    private void initViews() {
        nameText = (TextView) findViewById(R.id.delete_file_dialog_text);
        tv_titile = (TextView) findViewById(R.id.delete_file_dialog_tv_titile);
        ok = (Button) findViewById(R.id.delete_file_dialog_bt_ok);
        cancel = (Button) findViewById(R.id.delete_file_dialog_bt_cancel);

    }

    private void initEvens() {
        nameText.setText(name);
        tv_titile.setText(title);
        cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(mIDeleteFileDialogListener != null){
                    mIDeleteFileDialogListener.cancel();
                }
            }
        });
        ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(mIDeleteFileDialogListener != null){
                    mIDeleteFileDialogListener.confirm();
                }
            }
        });

    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            hideNavigationBar();
        }
    }

    /***
     * 全屏 隐藏底部虚拟按键
     */
    private void hideNavigationBar() {
        // TODO Auto-generated method stub
        final View decorView = getWindow().getDecorView();
        final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(flags);
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(flags);
                }
            }
        });
    }


}
